<template lang="pug">
  div
    el-divider
    el-card
      h2 HOME 任务分配 当前可用内存{{data[0].d.maxRam-data[0].d.ramUsed}}
      h2 当前操作单元配置 {{hackNum}}-{{growNum}}-{{weakenNum}}
      div.optionUnit hack
        el-input-number(v-model="hackNum" @change="handleChange" :min="1" :max="10" label="hack" size='mini')
      div.optionUnit grow
        el-input-number(v-model="growNum" @change="handleChange" :min="1" :max="10" label="grow" size='mini')
      div.optionUnit weaken
        el-input-number(v-model="weakenNum" @change="handleChange" :min="1" :max="10" label="weaken" size='mini')
    el-divider
    el-table(
      :data="data"
      stripe
      style="width: 100%")
      el-table-column(
        prop="s"
        label="服务器"
        width="180")
      el-table-column(
        prop="s"
        label="最大金额"
        width="180")
        template(slot-scope="scope") {{scope.row.d.moneyMax}}
      el-table-column(
        prop="s"
        label="余额"
        width="180")
        template(slot-scope="scope") {{scope.row.d.moneyAvailable.toFixed(2)}}
          el-progress(v-if='scope.row.d.moneyMax>0' :percentage="parseInt(scope.row.d.moneyAvailable/scope.row.d.moneyMax*100)" :format="format")
      el-table-column(
        prop="s"
        label="操作"
        width="280")
        template(slot-scope="scope")
          el-button(type='danger' size='mini') Kill All
          el-button(type='danger' size='mini') Kill Actions
      el-table-column(
        prop="s"
        label="权限"
        width="80")
        template(slot-scope="scope")
          i.el-icon-success(v-if='scope.row.d.hasAdminRights' style='color:#67C23A')
          i.el-icon-error(v-else style='color:#F56C6C')
      el-table-column(
        prop="s"
        label="后门"
        width="80")
        template(slot-scope="scope")
          i.el-icon-success(v-if='scope.row.d.backdoorInstalled' style='color:#67C23A')
          i.el-icon-error(v-else style='color:#F56C6C')
      el-table-column(
        prop="s"
        label="FTP"
        width="80")
        template(slot-scope="scope")
          i.el-icon-success(v-if='scope.row.d.ftpPortOpen' style='color:#67C23A')
          i.el-icon-error(v-else style='color:#F56C6C')
      el-table-column(
        prop="s"
        label="HTTP"
        width="80")
        template(slot-scope="scope")
          i.el-icon-success(v-if='scope.row.d.httpPortOpen' style='color:#67C23A')
          i.el-icon-error(v-else style='color:#F56C6C')
      el-table-column(
        prop="s"
        label="SMTP"
        width="80")
        template(slot-scope="scope")
          i.el-icon-success(v-if='scope.row.d.smtpPortOpen' style='color:#67C23A')
          i.el-icon-error(v-else style='color:#F56C6C')
      el-table-column(
        prop="s"
        label="SQL"
        width="80")
        template(slot-scope="scope")
          i.el-icon-success(v-if='scope.row.d.sqlPortOpen' style='color:#67C23A')
          i.el-icon-error(v-else style='color:#F56C6C')
      el-table-column(
        prop="s"
        label="SSH"
        width="80")
        template(slot-scope="scope")
          i.el-icon-success(v-if='scope.row.d.sshPortOpen' style='color:#67C23A')
          i.el-icon-error(v-else style='color:#F56C6C')
      el-table-column(
        prop="s"
        label="最低难度"
        width="180")
        template(slot-scope="scope") {{scope.row.d.minDifficulty}}
      el-table-column(
        prop="s"
        label="hack难度（倍率）"
        width="180")
        template(slot-scope="scope") {{(scope.row.d.hackDifficulty/scope.row.d.minDifficulty).toFixed(2)}}
      el-table-column(
        prop="s"
        label="内存"
        width="180")
        template(slot-scope="scope") {{scope.row.d.maxRam}}
      el-table-column(
        prop="s"
        label="已用内存"
        width="180")
        template(slot-scope="scope") {{scope.row.d.ramUsed}}
      el-table-column(
        prop="s"
        label="需要端口"
        width="80")
        template(slot-scope="scope") {{scope.row.d.numOpenPortsRequired}}
      el-table-column(
        prop="s"
        label="开放端口"
        width="80")
        template(slot-scope="scope") {{scope.row.d.openPortCount}}
      el-table-column(
        prop="s"
        label="等级"
        width="80")
        template(slot-scope="scope") {{scope.row.d.requiredHackingSkill}}
      el-table-column(
        prop="s"
        label="增长速度"
        width="80")
        template(slot-scope="scope") {{scope.row.d.serverGrowth}}
      el-table-column(
        prop="s"
        label="组织名称"
        width="280")
        template(slot-scope="scope") {{scope.row.d.organizationName}}
</template>

<script>
export default {
  name: 'servers',
  components: {},
  props: {
    socket: Object
  },
  data () {
    return {
      data: {},
      hackNum: 1,
      growNum: 1,
      weakenNum: 1
    }
  },
  mounted: function () {
    let that = this
    this.getData()
    setInterval(function () {
      that.getData()
    }, 1000)
  },
  methods: {
    getData: function () {
      let that = this
      that.loading = true
      that.$axios
        .post(that.$root.URL + '/server')
        .then(function (response) {
          that.data = response.data.data
        })
        .catch(function (error) {
          console.log(error)
          that.loading = false
          that.$message.error(error.toString())
        })
    }
  }
}
</script>

<!-- Add "scoped" attribute to limit CSS to this component only -->
<style scoped>
.optionUnit{
  display: inline;
  margin: 0 10px;
}
</style>
